package com.atguigu.MyTest;

import java.sql.SQLException;

/**
 * @author haoranlu
 * @project IntelliJ IDEA
 */
public class UserDAOImp1 extends BasicDAO<User> implements UserDAO{
    @Override
    public User getUser(User user) {
    String sql = "select * from users where username= ? and password = password(?)";
        User u = getBean(sql,user.getUsername(),user.getPassword());
        return u;
    }

    @Override
    public boolean checkUserName(String username) {
        String sql = "select * from users where username = ?";
        User user = getBean(sql, username);

        if (user == null) {
            return false;
        }
        return true;
    }


    @Override
    public void SaveUser(User user) {
    String sql = "insert into users values(null,?,?,?)";
        try {
            update(sql,user.getUsername(),user.getPassword(),user.getEmail());
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
